import java.util.Random;

import cn.chencq.adbdemo.ShellUtils;

public class BrowseUrl {

	private static String[] vpnArray = { "hb01", "hb02", "hb03", "hb04", "hb05", "hb06", "hb07", "hb08", "hb9" };

	public static void main(String[] args) {
		int cnt = 0;
		do {
			// 1.切换飞行模式
			// ShellUtils.shell("settings put global airplane_mode_on 1");
			// ShellUtils.shell("am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true");
			// sleep(10);

			// ShellUtils.shell("settings put global airplane_mode_on 0");
			// ShellUtils.shell("am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false");
			String vpnName = vpnArray[new Random().nextInt(9)];
			// 1.连接vpn
			ShellUtils.shell(String.format("rasdial %s chencq ccq901027", vpnName));
			System.out.println("vpn 已连接");
			// 2.启动浏览器，访问网页
			ShellUtils.shell("am start -a android.intent.action.VIEW -d http://2048.chencq.cn");
			sleep(new Random().nextInt(50));

			// 3.清除浏览器缓存
			ShellUtils.shell("pm clear com.android.browser");
			cnt++;
			System.out.println("执行次数：" + cnt);

			// 4.断开vpn
			ShellUtils.cmd(String.format("rasdial %s  /disconnect", vpnName));
			System.out.println("vpn 已断开连接");
		} while (cnt < 2000);

	}

	public static void sleep(int s) {
		try {
			Thread.sleep(s * 1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
